package com.bauer.java.springboot.simpleapp.controller;

import com.bauer.java.springboot.simpleapp.dto.BaseResponse;
import com.bauer.java.springboot.simpleapp.service.DemoService;
import com.bauer.java.springboot.simpleapp.service.UserCglib;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/springboot")
public class HelloSpringBoot {

    private static Logger logger = LoggerFactory.getLogger(HelloSpringBoot.class);

    @Autowired
    private DemoService demoSerivce;

    @Autowired
    private UserCglib userCglib;

    @RequestMapping("hello")
    public String hello() throws InterruptedException {
        for (int i = 0; i < 25; i++) {
            demoSerivce.test(i);
        }
        return "hello spring boot!";
    }

    @RequestMapping("/test")
    public String test(){
        userCglib.getUser();
        return "hello";
    }

    /**
     * 同一个class中调用不会生效  因为切面的原因
     *
     *
     * The default advice mode for processing @Async annotations is proxy which allows for interception of calls through
     * the proxy only. Local calls within the same class cannot get intercepted that way. For a more advanced mode of
     * interception, consider switching to aspectj mode in combination with compile-time or load-time weaving.
     */
    @Async
    public void test(int i) {
        logger.info("hello number{}", i);
    }
}
